<div class="gist_panel">
    <div class="gist_lookup"></div>
</div>

<div class="form_item required">
    <div class="form_item_block">
        <%= label_tag scope[:command_id] = random_dom_id('command_'), required_label_text('Command') -%>
        <%= scope[:form].text_field com.thoughtworks.go.config.ExecTask::COMMAND, {:class => "form_input required exec-task-command", :id => scope[:command_id]} -%>
        <div class="contextual_help has_go_tip_right" title="The command or script to be executed, relative to the working directory"></div>
        <%= error_message_on(scope[:task], com.thoughtworks.go.config.ExecTask::COMMAND, :css_class => "form_error") %>
    </div>

    <div class="form_item_block">
        <div>
            <%= label_tag scope[:arguments_id] = random_dom_id('arguments_'), 'Arguments' -%>
        </div>
        <% if !scope[:task].getArgs().empty? %>
            <%= scope[:form].text_field com.thoughtworks.go.config.ExecTask::ARGS, {:class => "form_input", :id => scope[:arguments_id]} -%>
            <%= error_message_on(scope[:task], com.thoughtworks.go.config.ExecTask::ARGS, :css_class => "form_error") %>
        <% else %>
            <% scope[:task].getArgList().each do |argument|
                error = argument.errors().on(com.thoughtworks.go.config.ExecTask::ARG_LIST_STRING)
                if error
                    scope[:task].errors().add(com.thoughtworks.go.config.ExecTask::ARG_LIST_STRING, error)
                end
            end %>
            <%= scope[:form].text_area com.thoughtworks.go.config.ExecTask::ARG_LIST_STRING, {:class => "form_input code_text exec-task-arguments", :wrap => "off" , :rows => 5, :cols => 50, :id => scope[:arguments_id]} -%>
            <div style='margin:3px 0 10px;' class="inline_instruction">
                Enter each argument on a new line
            </div>
            <%= error_message_on(scope[:task], com.thoughtworks.go.config.ExecTask::ARG_LIST_STRING, :css_class => "form_error") %>
        <% end %>
    </div>

    <div class="form_item_block">
        <%= label_tag scope[:work_dir_id] = random_dom_id('working_dir_'), 'Working Directory' -%>
        <%= scope[:form].text_field com.thoughtworks.go.config.ExecTask::WORKING_DIR, {:class => "form_input", :id => scope[:work_dir_id]} -%>
        <div class="contextual_help has_go_tip_right" title="The directory in which the script or command is to be executed. This is always relative to the directory where the agent checks out materials."></div>
        <%= error_message_on(scope[:task], com.thoughtworks.go.config.ExecTask::WORKING_DIR, :css_class => "form_error") %>
    </div>
</div>
<script type="text/javascript">
    Util.on_load(function() {
        jQuery.get("<%= admin_commands_path -%>", [], function(data) {
            jQuery(".gist_lookup").html(data);
            if(data){
                jQuery(".gist_lookup").addClass("form_item")
            }
            var command_definition_url = "<%= admin_command_definition_path -%>";
            var commandLookupUrl = "<%= admin_command_lookup_path -%>";
            var task_selector = "#task .task.fieldset";
            var on_cancel_task_selector = "#task .on_cancel.fieldset";
            var new_pipeline__task_selector = "<%= ".task_entry." + com.thoughtworks.go.config.ExecTask.new.getTaskType() -%>";

            TaskSnippet.attachClickHandlers(task_selector, commandLookupUrl, command_definition_url, ".exec-task-command", ".exec-task-arguments");

            TaskSnippet.attachClickHandlers(on_cancel_task_selector, commandLookupUrl, command_definition_url, ".exec-task-command", ".exec-task-arguments");

            TaskSnippet.attachClickHandlers(new_pipeline__task_selector, commandLookupUrl, command_definition_url, ".exec-task-command", ".exec-task-arguments");
        });
    });
</script>
